﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace App14._1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : BaseWindow
    {
        static Window1()
        {
            ExtendProperty.OverrideMetadata(typeof(Window1), new
            PropertyMetadata(ExtendChanged));
        }

        public Window1()
            : base()
        {
            InitializeComponent();
        }

        public void OnLoaded(object sender, RoutedEventArgs args)
        {
            Extend = true;
        }

        public static void ExtendChanged(DependencyObject obj,
            DependencyPropertyChangedEventArgs args)
        {
            MessageBox.Show("Window1's Extend property changed!");
        }
    }

    public class BaseWindow : System.Windows.Window
    {
        public BaseWindow()
            : base()
        { }

        public static void ExtendChangedBase(DependencyObject obj,
            DependencyPropertyChangedEventArgs args)
        {
            MessageBox.Show("BaseWindow's Extend property changed!");
        }

        public bool Extend
        {
            get { return (bool)GetValue(ExtendProperty); }
            set { SetValue(ExtendProperty, value); }
        }

        public static readonly DependencyProperty ExtendProperty =
            DependencyProperty.Register("Extend", typeof(bool), typeof(BaseWindow),
            new PropertyMetadata(ExtendChangedBase));
    }
}
